package cn.edu.fudan.tools;

import cn.edu.fudan.type.DataItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 80494 on 2017/3/15.
 * just a test , unuseful now
 */
public class MyPaa {
    private ArrayList<Double> ts;
    private double means;

    private double srd ;
    private ArrayList normts;
    private long origlenth;
    private long shrunksize;

    public MyPaa(List<DataItem> data) throws Exception{
        this.ts = this.ItemToTs(data);
        this.means = this.GetMeans(ts);
        this.srd = this.GetStandardDevition(ts);


        //if (shrunksize > ts.size())
        //    throw new RuntimeException("ERROR:  The size of an aggregate representation may not be largerr than the \n" +
        //            "original time series (shrunkSize=" + shrunksize + " , origSize=" + ts.size() + ").");
//
        //if (shrunksize <= 0)
      //      throw new RuntimeException("ERROR:  The size of an aggregate representation must be greater than zero and \n" +
       //             "no larger than the original time series.");



    }


    private ArrayList<Double> ItemToTs (List<DataItem> data ) throws Exception{
        this.ts = new ArrayList<Double>();
        for (DataItem item:data) {
            this.ts.add(item.getValue());
        }
        return this.ts;
    }
    public ArrayList<Double> Znorm(List<DataItem> data ) throws Exception{
        ArrayList<Double> time = this.ItemToTs(data);
        ArrayList<Double> newtime = new ArrayList<Double>();
        this.means = this.GetMeans(time);
        this.srd = this.GetStandardDevition(time);
        for(int i=0 ; i< time.size();i++){
            Double newnum = (time.get(i)-this.means)/this.srd;
            newtime.set(i,newnum);
        }
        return newtime;

    }





    private double GetMeans(ArrayList<Double> list){
        double sum  = 0;
        for(int i = 0;i<list.size();i++){
            sum += list.get(i);
        }
        return sum/list.size();
    }
    private  double GetStandardDevition(ArrayList<Double> list){
        double sums = 0;

        for(int i = 0;i < list.size();i++){
            sums += Math.sqrt(((double)list.get(i) -this.means) * (list.get(i) -this.means));
        }
        return (sums / (list.size() - 1));
    }
}
